package com.hjm.project.salaryPlan.agentActivity.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.salaryPlan.agentActivity.domain.AgentActivity;
import com.hjm.project.salaryPlan.agentActivity.service.IAgentActivityService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import javax.annotation.Resource;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 代理商活动Controller
 * 
 * @author maker-platform
 * @date 2022-04-07
 */
@Controller
@RequestMapping("/salaryPlan/agentActivity")
public class AgentActivityController extends BaseController {
    private String prefix = "salaryPlan/agentActivity";

    @Resource
    private IAgentActivityService agentActivityService;

    @RequiresPermissions("salaryPlan:agentActivity:view")
    @GetMapping()
    public String agentActivity() {
        return prefix + "/agentActivity";
    }

    /**
     * 活动查找带回页面
     * @Param []
     * @Return java.lang.String
     */
    @GetMapping("selectAgentActivityList")
    public String selectAgentActivityList() {
        return prefix + "/selectAgentActivityList";
    }

    /**
     * 查询代理商活动列表
     */
    @RequiresPermissions("salaryPlan:agentActivity:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AgentActivity agentActivity) {
        startPage();
        List<AgentActivity> list = agentActivityService.selectAgentActivityList(agentActivity);
        return getDataTable(list);
    }

    /**
     * 导出代理商活动列表
     */
    @RequiresPermissions("salaryPlan:agentActivity:export")
    @Log(title = "代理商活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AgentActivity agentActivity) {
        List<AgentActivity> list = agentActivityService.selectAgentActivityList(agentActivity);
        ExcelUtil<AgentActivity> util = new ExcelUtil<AgentActivity>(AgentActivity.class);
        return util.exportExcel(list, "agentActivity");
    }

    /**
     * 新增代理商活动
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存代理商活动
     */
    @RequiresPermissions("salaryPlan:agentActivity:add")
    @Log(title = "代理商活动", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AgentActivity agentActivity) {
        return toAjax(agentActivityService.insertAgentActivity(agentActivity));
    }

    /**
     * 修改代理商活动
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        AgentActivity agentActivity = agentActivityService.selectAgentActivityById(id);
        mmap.put("agentActivity", agentActivity);
        return prefix + "/edit";
    }

    /**
     * 修改保存代理商活动
     */
    @RequiresPermissions("salaryPlan:agentActivity:edit")
    @Log(title = "代理商活动", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AgentActivity agentActivity) {
        return toAjax(agentActivityService.updateAgentActivity(agentActivity));
    }

    /**
     * 删除代理商活动
     */
    @RequiresPermissions("salaryPlan:agentActivity:remove")
    @Log(title = "代理商活动", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(agentActivityService.deleteAgentActivityByIds(ids));
    }
}
